fix: better error handling for negative size of FixedSizeBinary#10042
Conversation
Jefffrey
left a comment
There was a problem hiding this comment.
Do we have a test case from the original issue? I think DataFusion was calling a parse code path in arrow-rs, so maybe look to add the test case there? (parsing a datatype from string, I mean)
Not anything I am aware of- can introduce one later. Anyway, writing such a test will be much easier if we have |
|
Maybe @Jefffrey was talking about arrow-rs/arrow-schema/src/datatype.rs Lines 495 to 507 in f1ef71a In the sense that it perhaps more likely for someone to be able to feed negative numbers in via SQL than via Rust APIs. So in this case case, |
|
Thank you for pointing it out. I've added a check into the parser and a test for it. |
| fn parse_fixed_size_binary(&mut self) -> ArrowResult<DataType> { | ||
| self.expect_token(Token::LParen)?; | ||
| let length = self.parse_i32("FixedSizeBinary")?; | ||
| if length < 0 { |
There was a problem hiding this comment.
Is FixedSizeBinary(0) allowed? I think this check only verifies >= 0 🤔
There was a problem hiding this comment.
The format doesn't tell anything about it. The C++ implementation allows zero-width buffer. Fixed an error message
…he#10042) # Which issue does this PR close? <!-- We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. --> - Closes apache#10033. # Rationale for this change Related to apache/datafusion#22297, where using `FixedSizeBinary(-N)` caused failures. Actually, it will still panic, but with a proper error. It could be a good idea to introduce `try_new_null` to carry an error gracefully - thoughts? # What changes are included in this PR? - Return a `Result` on negative byte width when possible - Panic explicitly with a proper error message otherwise - Avoid silent overflow with a direct `len as usize` cast - Reject negative FSB when parsing from tokens # Are these changes tested? - Tests are passing # Are there any user-facing changes? No
Which issue does this PR close?
Rationale for this change
Related to apache/datafusion#22297, where using
FixedSizeBinary(-N)caused failures. Actually, it will still panic, but with a proper error. It could be a good idea to introducetry_new_nullto carry an error gracefully - thoughts?What changes are included in this PR?
Resulton negative byte width when possiblelen as usizecastAre these changes tested?
Are there any user-facing changes?
No